function initSocket(uid, nickname) {
  //判断当前浏览器是否支持WebSocket
  if ("WebSocket" in window) {
    websocket = io.connect(
      "http://127.0.0.1:8036/im/user?userid=" +
        uid +
        "&nickname=" +
        nickname +
        "&origin=customer&event=connect&islogin=0&scene=kf&targetType=0",
      { transports: ["websocket", "xhr-polling", "jsonp-polling"] }
    );
  } else {
    layer.msg(unSupportWsMsg, { anim: 6 });
  }

  //连接成功的状态信息
  websocket.on("status", function (data) {
    console.log(data);
    let statusMessage = JSON.parse(data.statusMessage);
    targetId = statusMessage.targetId;
    sessionId = statusMessage.sessionId;
    scene = statusMessage.scene;
    userId = statusMessage.userId;
    targetType = statusMessage.targetType;
    alert(data.message);
  });

  websocket.on("hismessage", function (data) {
    let statusMessage = JSON.parse(data.statusMessage);
    statusMessage.forEach((element) => {
      putMsg(element);
    });
  });

  //接收到消息的回调方法
  websocket.on("message", function (event) {
    putMsg(event);
  });

  //连接关闭的回调方法
  websocket.onclose = function () {
    layer.alert(oncloseMsg, { icon: 2 });
    $("#footer").animate({ bottom: "-200px" }, 400);
  };
}